package com.itheima.service.impl;

import com.itheima.bean.Student;
import com.itheima.mapper.StudentMapper;
import com.itheima.service.StudentService;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

@Service("studentService")
public class StudentServiceImpl implements StudentService {

    @Autowired
    private StudentMapper mapper;


    @Override
    public List<Student> selectAll() throws IOException {
        //执行操作
        List<Student> list = mapper.selectAll();
        return list;
    }

    @Override
    public Student selectById(Integer id) throws IOException {
        //执行代理对象的方法
        Student student = mapper.selectById(id);   //底层使用sqlSession.selectOne()方法
        return student;
    }

    @Override
    public Integer insert(Student stu) throws IOException {
        //执行代理对象的方法
        Integer count = mapper.insert(stu);   //底层使用sqlSession.selectOne()方法
        return count;
    }

    @Override
    public Integer update(Student stu) throws IOException {
        //执行代理对象的方法
        Integer count = mapper.update(stu);   //底层使用sqlSession.selectOne()方法
        return count;
    }

    @Override
    public Integer delete(Integer id) throws IOException {
        Integer count = mapper.delete(id);
        return count;
    }
}
